﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ettevotja_dokument", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(EttevotjaDokument))]
    public class EttevotjaDokumentSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IEttevotjaDokument clazz;
        
        public EttevotjaDokumentSerializer(IEttevotjaDokument clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("dokumendi_id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.DokumendiId))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("ariregistri_kood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AriregistriKood))).ToString());
            Writer.WriteEndElement();
            if (clazz.DokumendiLiik!=null) {
                Writer.WriteStartElement("dokumendi_liik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiLiik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.DokumendiNimetus!=null) {
                Writer.WriteStartElement("dokumendi_nimetus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiNimetus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.DokumendiSuurus!=null) {
                Writer.WriteStartElement("dokumendi_suurus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.DokumendiSuurus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.DokumendiSeisuKuupaev!=null) {
                Writer.WriteStartElement("dokumendi_seisu_kuupaev");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.DokumendiSeisuKuupaev))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.DokumendiKehtivus!=null) {
                Writer.WriteStartElement("dokumendi_kehtivus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiKehtivus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AruandeLiik!=null) {
                Writer.WriteStartElement("aruande_liik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AruandeLiik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Aruandeaasta!=null) {
                Writer.WriteStartElement("aruandeaasta");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Aruandeaasta))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.DokumendiUrl!=null) {
                Writer.WriteStartElement("dokumendi_url");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiUrl))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="dokumendi_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_dokument>dokumendi_id");
                }
                clazz.DokumendiId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("dokumendi_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ettevotja_dokument>dokumendi_id", Reader.LocalName);
            }
            if (Reader.LocalName=="ariregistri_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_dokument>ariregistri_kood");
                }
                clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ariregistri_kood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ettevotja_dokument>ariregistri_kood", Reader.LocalName);
            }
            if (Reader.LocalName=="dokumendi_liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_dokument>dokumendi_liik");
                }
                clazz.DokumendiLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("dokumendi_liik")).Value;
            }
            if (Reader.LocalName=="dokumendi_nimetus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_dokument>dokumendi_nimetus");
                }
                clazz.DokumendiNimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("dokumendi_nimetus")).Value;
            }
            if (Reader.LocalName=="dokumendi_suurus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_dokument>dokumendi_suurus");
                }
                clazz.DokumendiSuurus = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("dokumendi_suurus")).Value;
            }
            if (Reader.LocalName=="dokumendi_seisu_kuupaev") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_dokument>dokumendi_seisu_kuupaev");
                }
                clazz.DokumendiSeisuKuupaev = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("dokumendi_seisu_kuupaev")).Value;
            }
            if (Reader.LocalName=="dokumendi_kehtivus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_dokument>dokumendi_kehtivus");
                }
                clazz.DokumendiKehtivus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("dokumendi_kehtivus")).Value;
            }
            if (Reader.LocalName=="aruande_liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_dokument>aruande_liik");
                }
                clazz.AruandeLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("aruande_liik")).Value;
            }
            if (Reader.LocalName=="aruandeaasta") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_dokument>aruandeaasta");
                }
                clazz.Aruandeaasta = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("aruandeaasta")).Value;
            }
            if (Reader.LocalName=="dokumendi_url") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_dokument>dokumendi_url");
                }
                clazz.DokumendiUrl = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("dokumendi_url")).Value;
            }
        }
    }
}
